uniform sampler2D tex;
uniform sampler2D ntex;
uniform sampler2D htex;

varying vec4 vcol;
varying vec3 lvec,vvec,hvec;

void main() {
	// parallax mapping
	vec2 texUV, srcUV = gl_TexCoord[0].xy;
	float height = texture2D(htex, srcUV).r;
	float v = height * 0.04 - 0.02;
	vec3 vv 	= normalize(vvec);
	
	texUV = srcUV + (vv.xy * v);
	
	// colours
	vec4 ambient_color  = vec4(0.05);
	vec4 diffuse_color 	= vec4(0.8);
	vec4 specular_color = vec4(0.4);
	
	vec4 colormap 		= texture2D(tex, texUV);
	
	vec3 lv 	= normalize(lvec);
	
	vec3 nv 	= normalize(2.0*texture2D(ntex, texUV).xyz-1.0);
	

	float diff 	= max(dot(lv, nv), 0.0);
	float spec	= pow(max(dot(reflect(-vv, nv), lv),0.0), 100.0);

	vec4 diff_pass = colormap*(diff*diffuse_color) + ambient_color;
	vec4 spec_pass = spec*specular_color;	
	gl_FragColor = (diff_pass  + spec_pass);
}
